package sy.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import sy.db.mysql.model.JKGL;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.services.JKGLServiceI;

/**
 *  @author zxl
 */
@Controller
@RequestMapping("/jkglController")
public class JKGLController extends BaseController {
	@Autowired
	public JKGLServiceI jKGLService;

	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid dataGrid(@RequestParam  Map param) {
		return jKGLService.findbyByGrid(param);
	}
	
	@RequestMapping("/add.shtml")
	@ResponseBody
	public Json add(JKGL t , HttpSession session,NativeWebRequest request) {
		
	
		Json j = new Json();
		try {
			jKGLService.insert(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/edit.shtml")
	@ResponseBody
	public Json edit(JKGL t , HttpSession session,NativeWebRequest request) {
		
		
		Json j = new Json();
		try {
			
			jKGLService.updateByPrimaryKeySelective(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete.shtml")
	@ResponseBody
	public Json delete(String id) {
		Json j = new Json();
		try {
			jKGLService.deleteByPrimaryKey(id);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/selectByid.shtml")
	@ResponseBody
	public JKGL selectByid(String id) {
		return jKGLService.selectByPrimaryKey(id);
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/manager.shtml")
	public String manager() {
		return "/jkgl/jkgl_list";
	}
	@RequestMapping("/jkgl_kt_gb_ty.shtml")
	public String jkgl_kt_gb_ty() {
		return "/jkgl/jkgl_kt_gb_ty";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/addPage.shtml")
	public String addPage(HttpServletRequest request) {
	return "/jkgl/jkgl_Add";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/editPage.shtml")
	public String editPage(String id ,HttpServletRequest request) {
		JKGL jKGL = this.jKGLService.selectByPrimaryKey(id);
		request.setAttribute("jKGL", jKGL);
		return "/jkgl/jkgl_edit";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/viewPage.shtml")
	public String viewPage(String id ,HttpServletRequest request) {
		JKGL jKGL = this.jKGLService.selectByPrimaryKey(id);
		request.setAttribute("jKGL", jKGL);
		return "/jKGL/jKGLView";
	}
}
